#include <setjmp.h>
#include "Scanner.h"
#include "parser.h"
#include "vm.h"

int main(int argc, char* argv[])
{
	int parseret;

	if(argc < 2)
	{
		fprintf(stderr, "Usage: %s FILENAME\n", argv[0]);
		return 1;
	}

	if((inputStreamScanner = fopen(argv[1], "r")) == NULL)
	{
		fprintf(stderr, "Unable to open file %s\n", argv[1]);
		return 1;
	}

	InitializeScanner();
    ReadFile();
    OutputCode(stdout);

	fprintf(stdout, "\n\n");

    OutputLexemeTable(stdout);

    fprintf(stdout, "\n\n");

    OutputLexemeList(stdout);

    fclose(inputStreamScanner);

    fprintf(stdout, "\n\n");

	parseret = parse_program();
	if(!parseret)
		return 1;

	printf("\nNo errors, program syntactically correct.\n");
	
	vm();

	return 0;
}

